package com.csjy.migration.hnnd.workflow;

import com.csjy.migration.hnnd.DbUtil;
import com.csjy.migration.hnnd.ProgramArgument;
import com.csjy.migration.hnnd.Tool;
import com.csjy.migration.hnnd.annotation.Task;
import com.csjy.migration.hnnd.business.SourceBusinessData;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 提交检查报告流程
 */
public class ItemCheckrptSubmitHny extends WorkflowMigration {

  public ItemCheckrptSubmitHny(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId, Map procInstRow) throws Exception {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, procInstId, procInstRow);
    this.customInitData();
  }

  @Override
  public void customInitData() throws SQLException {
    this.curBizType = "tjjcbg";
  }

  @Override
  public void customInsertOrUpdateData() throws SQLException {

  }


  @Task("提交检查报告@项目经理提交检查报告")
  public void  tjjcbgxmjltjjcbg() throws Exception{

    this.curAffixType =  "jcbg";
    // 附件列表
    this.curAffixTypeCommon = "tjjcbg";
    // 查询
    Map map = new HashMap();
    for(int i = 0;i<this.sourceData.getBtItemCheckReportBasic().size();i++) {
      Map btItemCheckReportBasic = this.sourceData.getBtItemCheckReportBasic().get(i);
      if(btItemCheckReportBasic.get("WORKFLOWNO").toString().equals(this.procInstId)){
        map = btItemCheckReportBasic;
        break;
      }
    }

    this.curCustomData.put("cooperateAttitude",map.get("SUPPORTATTITUDE"));//配合态度
    this.curCustomData.put("inspectionType",map.get("CHECKTYPE"));//检查类型
    this.curCustomData.put("alarmLevel",map.get("ALARMLEVEL"));//报警级别

    // 将时间转换成yyyy-MM-dd
    Object checkDate = map.get("CHECKDATE");
    String dateString = null;
    if(checkDate != null && checkDate instanceof Date){
      Date date = (Date) checkDate;
      dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
    }
    this.curCustomData.put("checkDate",dateString);//检查日期
    this.curCustomData.put("receptionName",map.get("RECCEPTERNAME"));//接待人名
    this.curCustomData.put("contactNumber",map.get("RECCEPTERTEL"));//联系电话
    this.curCustomData.put("checkDescription", Tool.replaceBrFlagStr(map.get("NOTICEMEMO")));//

    this.curModelMap.put("提交审核", new String[]{"task1535356489817tjsh","提交审核"});
    this.curModelMap.put("提交办事处", new String[]{"task1535356489817tjsh","提交审核"});
    this.curModelMap.put("提交分公司", new String[]{"task1535356489817tjsh","提交审核"});

    if(this.curNextStepUserIds != null) {
      this.actHiVarinstMap.put("task1535356489817",this.curNextStepUserIds);
    }

    this.setCommonData(true,null);

    // procFormStr
    if(map.get("CHECKNO") != null){
      this.procFormStrMap.put("submitInspectionReportId", map.get("CHECKNO"));
    }
    this.procFormStrMap.put("cooperateAttitude",map.get("SUPPORTATTITUDE"));//配合态度
    this.procFormStrMap.put("inspectionType",map.get("CHECKTYPE"));//检查类型
    this.procFormStrMap.put("alarmLevel",map.get("ALARMLEVEL"));//报警级别
    this.procFormStrMap.put("checkDate",dateString);//检查日期
    this.procFormStrMap.put("receptionName",map.get("RECCEPTERNAME"));//接待人名
    this.procFormStrMap.put("contactNumber",map.get("RECCEPTERTEL"));//联系电话
    this.procFormStrMap.put("checkDescription", Tool.replaceBrFlagStr(map.get("NOTICEMEMO")));//

    // TODO:财务报告数据

  }

  @Task("提交检查报告@BC经理审核")
  public void tjjcbgBCjlsh() throws Exception {
    this.curAffixType = "tjfj";


    this.curModelMap.put("提交审核", new String[]{"exclusiveGateway1596072236919tg","通过"});
    // todo 旧系统 bc经理审核节点有通过和同意,暂时不知道走到什么节点,无法正确映射
    this.curModelMap.put("通过", new String[]{"exclusiveGateway1596072236919tg","通过"});
    this.curModelMap.put("同意", new String[]{"exclusiveGateway1596072236919tg","通过"});

    this.setCommonData(true,null);

    if(this.curNextStepUserIds != null) {
      this.actHiVarinstMap.put("task1599123282069",this.curNextStepUserIds);
    }
  }

  @Task("提交检查报告@办事处负责人审核")
  public void  tjjcbgbshfzrsh() throws Exception {
    this.curModelMap.put("通过", new String[]{"task1561105043289xyb","下一步"});
    this.setCommonData(false,null);
  }


  @Task("提交检查报告@分公司负责人审核")
  public void tjjcbgfgsfzrsh() throws Exception {
    this.curModelMap.put("通过", new String[]{"task1535356496900tg","通过"});
    this.setCommonData(false,null);
  }


  @Task("提交检查报告@风控部副经理审核")
  public void  tjjcbgfkbfjlsh() throws Exception{
    this.curModelMap.put("结束", new String[]{"endjs","结束"});
    this.curModelMap.put("上发", new String[]{"task1535356499156sf","上发"});



    this.curCustomData.put("reportRating",this.getJbpmVarInstValueByName("reportMark"));//报告评分


    this.setCommonData(false,null);
  }




  @Task("提交检查报告@部门风控经理审核")
  public void  tjjcbgbmfkjlsh() throws Exception {
    this.curModelMap.put("通过", new String[]{"exclusiveGateway1599126833866xyb","下一步"});
    // todo 需要知道同意节点的流转
    this.curModelMap.put("同意", new String[]{"exclusiveGateway1599126833866xyb","下一步"});
    this.setCommonData(false,null);
  }

  @Task("提交检查报告@董事长查看")
  public void  tjjcbgdszck() throws Exception {
    this.curModelMap.put("通过", new String[]{"endtg","通过"});
    this.setCommonData(false,null);
  }




  @Task("提交检查报告@风控副总审核")
  public void  tjjcbgfkbfzsh() throws Exception{
    this.curCustomData.put("riskClassification",this.getJbpmVarInstValueByName("currentRiskLevel"));//报告评分
    this.curModelMap.put("结束", new String[]{"endjs","结束"});
    this.curModelMap.put("上发", new String[]{"task1535356501594sf","上发"});
    this.setCommonData(false,null);
  }



  @Task("提交检查报告@总经理审核")
  public void  tjjcbgzjlsh() throws Exception {
    this.curModelMap.put("结束", new String[]{"endjs","结束"});
    this.curModelMap.put("上发", new String[]{"task1535356504053sf","上发"});
    this.setCommonData(false,null);
  }


  @Task("提交检查报告@风控部经理审核")
  public void  tjjcbgfkbjlsh() throws Exception{
    this.tjjcbgbmfkjlsh();
  }

}